<template>
  <div class="dosth">
    <search-form
      :form-data="formData"
      @search="searchHandle"
      @reset="resetHandle"
      :label-width="170"
    ></search-form>

    <InnerPageTable ref="listTable" :config="pageTableConfig">
      <div slot="table-bar">
        <!-- <Button @click.native="batchSubmit">批量提交</Button>
        <Button v-show="false"></Button> -->
      </div>
    </InnerPageTable>
    <div class="btn_box" v-if="isShowBack">
      <Button type="default" @click.native='backHandle2'>返回</Button>
    </div>
  </div>
</template>

<script>
import SearchForm from "@/components/common/SearchForm"
import ruleDetails from "../ruleBaseManagement/pages/RuleDetails.vue";

import{configForm,generateColumns} from './js/commons'
import { mixin } from './js/mixin'
import todoListAPI from "@/api/todoListApi.js"
import ruleBaseAPI from "@/api/ruleBaseApi.js";
import { superviseInfoAPI } from "@api/superviseInfo";
import { homeMapping } from "@/tools/util";
import Vue from "vue";
import detailPage from "@/components/detailInfo";


export default {
  name: 'do-sth',
  components: {
    searchForm: SearchForm,
    ruleDetails
  },
  mixins: [mixin],
  props: {
    title: {
      type: String,
      default: ''
    },
    state: {
      type: Number,
      default:0
    },
    isShowBack: {
      type: Boolean,
      default: true
    },
    // todoList: {
    //   type: Array,
    //   default: []
    // }
  },
  computed: {
    formData() {
      return configForm.bind(this)()
    }
  },
  data() {
    return {
      // formData: configForm,
      pageTableConfig: {
        columns: generateColumns.bind(this)(),
        loadDataFn: this.getTableList,
        autoFirst: true,
        selectionAreaItem: { key: "id", title: "userName" },
        allSelection: [],
        initParam:{}
      }
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.$emit("SetTitle", this.title);
    },
    //返回按钮
    backHandle2() {
      this.$emit("Close");
    },

    getTableList(tableObj) {
      let { responseProcess, initParam, param } = tableObj;
      const params = {
        ...param,
        ...initParam
      }
      params.condition.state = this.state
      todoListAPI.querylist(params).then(res => {
        responseProcess(res.data);
        this.setUnhandledTips(res.data)
      })
    },

    setUnhandledTips(data) {
      // 查询的是待办列表
      if (this.state == 1 && data.total > 0) {
        window.$channel.$emit('unhandledNumChanged', data.total)
      }
    },

    batchSubmit() {
      console.log('批量提交')
    },

    detailHandle(row) {
      // console.log(row,'rowwwww')

      if (row.serviceType == 'RULE_MAINTENANCE') {
        // console.log(row.applicationNo,'=======applicationNo')
        // console.log(row.serviceType, '=======serviceType')
        let params ={
          "codeList": [],
          "dataItemName": "",
          "dataSubject": "",
          "describes": "",
          "functionModules": "",
          "idList": [],
          "stateList": [],
          "title": ""
        }
        let rowDetail={}
        let detailId = row.applicationNo
        params.idList.push(detailId)
        ruleBaseAPI.queryList1(params).then(res => {
          if (!res.data.length) {
            this.$message.error('数据不存在')
            return
          }else{
          if (res.data[0]) {
            rowDetail = res.data[0]
            // console.log(rowDetail, '=======res')
            if (rowDetail.bpmnState) {
              new this.$sidelipPage(ruleDetails, { props: { rowDetail, detailId, bpmnState: rowDetail.bpmnState, isDisabled: true, title: '详情信息(只读)' }, isNav: false },
                () => {
                  // 关闭时的回调
                  this.resetHandle()
                }
              );
            } else {
              new this.$sidelipPage(ruleDetails, { props: { rowDetail, detailId, title: '详情信息' }, isNav: false },
                () => {
                  // 关闭时的回调
                  this.resetHandle()
                }
              );
            }
          }
          }
        })
      } else {
        this.$Spin.show()
        superviseInfoAPI.detailPage({ id: row.applicationNo }, homeMapping[row.serviceType][0]).then(res => {
          this.$Spin.hide()
          if (!res.data) {
            this.$message.error('数据不存在')
            return
          }
          const detailInfo = res.data
          new Vue.prototype.$sidelipPage(detailPage, { props: { detailInfo, detailField: homeMapping[row.serviceType][1], tableBelong: homeMapping[row.serviceType][2] }, listId: row.applicationNo, isNav: false  })
        })
      }
    }
  }

}
</script>

<style lang="less" scoped>
.btn_box {
    text-align: right;
    position: fixed;
    bottom: 15px;
    right: 50px;
    background: #ffffff;
    z-index: 1000 !important;
  }
  .btn_box > *{
    margin-left: 10px;
    margin-bottom: 5px;
  }
</style>
